package cn.dnui_zzh807.dnuifood_16110100807.controller;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import cn.dnui_zzh807.dnuifood_16110100807.R;
import cn.dnui_zzh807.dnuifood_16110100807.bean.ResultBean;
import cn.dnui_zzh807.dnuifood_16110100807.listener.OnRetrofitListener;
import cn.dnui_zzh807.dnuifood_16110100807.model.UserModel;

public class Signin extends BaseActivity implements OnRetrofitListener<ResultBean> {
    private Intent intent;
    private UserModel userModel;
     private EditText et_reg_user,et_reg_password,et_reg_repassword,et_reg_telephone,et_reg_adress,et_reg_aomment;
     private Button register;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_signin);
       et_reg_user= findViewById(R.id.username1);
      et_reg_password = findViewById(R.id.userpass1);
      et_reg_repassword = findViewById(R.id.enpassword);
      et_reg_telephone = findViewById(R.id.phone1);
      et_reg_adress = findViewById(R.id.address1);
      et_reg_aomment = findViewById(R.id.comment1);
      register = findViewById(R.id.signin);

         initEvents();

}
private void register(){
        userModel = new UserModel();
        userModel.register(
                et_reg_user.getText().toString(),
                et_reg_password.getText().toString(),
                et_reg_telephone.getText().toString(),
                   et_reg_adress.getText().toString(),
                   et_reg_aomment.getText().toString()
                   ,this);

}

    @Override
    void initViews() {

    }

    @Override
void initEvents(){
 register.setOnClickListener(new View.OnClickListener() {
     @Override
     public void onClick(View view) {
         if (et_reg_password.getText().toString().equals(et_reg_repassword.getText().toString())){
             register();
         }else {
             showToast("请确认两次密码相同");
         }
     }
 });
}

    @Override
    void initData() {

    }

    @Override
    public void onSuccess(ResultBean result, int flag) {
        if (result.getSuccess().equals("1")){
            intent = new Intent();
            intent.putExtra("user",et_reg_user.getText().toString());
            setResult(RESULT_OK,intent);
            finish();
            showToast("注册成功");
        }else {
            showToast("注册失败");
        }
    }

    @Override
    public void onFail() {
      showToast("网络发生故障");
    }

}